import 'package:flutter/material.dart';
import 'login.dart';

class SettingDetail extends StatefulWidget {
  @override
  _SettingDetailState createState() => _SettingDetailState();
}
class _SettingDetailState extends State<SettingDetail> {
  void _handleItemClick(String item) {
    print('$item clicked');
  }
  void _handleLogout() {
    print('退出登录');
    // Navigate to the login page and remove all previous routes
    Navigator.of(context).pushAndRemoveUntil(
      MaterialPageRoute(builder: (context) => LoginPage()),
          (Route<dynamic> route) => false,
    );

  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('个人信息'),
        centerTitle: true,
      ),
      body: ListView(
        children: [
          Padding(
            padding: const EdgeInsets.only(top: 10.0),
            child: Container(
              color: Colors.white,
              child: Column(
                children: [
                  Container(
                    height: 100, // 设置第一行的高度为100
                    child: Center(
                      child: ListTile(
                        title: Text('头像'),
                        trailing: Row(
                          mainAxisSize: MainAxisSize.min,
                          children: [
                            CircleAvatar(
                              radius: 40,
                              backgroundImage: AssetImage('assets/default_avatar.png'), // 默认头像路径
                            ),
                            Icon(Icons.arrow_forward_ios),
                          ],
                        ),
                        onTap: () => _handleItemClick('头像'),
                      ),
                    ),
                  ),
                  Divider(height: 1),
                  ListTile(
                    title: Text('昵称'),
                    trailing: Row(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Text('13308622037'),
                        Icon(Icons.arrow_forward_ios),
                      ],
                    ),
                    onTap: () => _handleItemClick('昵称'),
                  ),
                ],
              ),
            ),
          ),
          Padding(
            padding: const EdgeInsets.only(top: 10.0),
            child: Container(
              color: Colors.white,
              child: Column(
                children: [
                  ListTile(
                    title: Text('用户协议'),
                    trailing: Icon(Icons.arrow_forward_ios),
                    onTap: () => _handleItemClick('用户协议'),
                  ),
                  Divider(height: 1),
                  ListTile(
                    title: Text('隐私条款'),
                    trailing: Icon(Icons.arrow_forward_ios),
                    onTap: () => _handleItemClick('隐私条款'),
                  ),
                  Divider(height: 1),
                  ListTile(
                    title: Text('账号注销'),
                    trailing: Icon(Icons.arrow_forward_ios),
                    onTap: () => _handleItemClick('账号注销'),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
      bottomNavigationBar: Padding(
        padding: const EdgeInsets.all(8.0),
        child: SizedBox(
          height: 60,
          child: ElevatedButton(
            onPressed: _handleLogout,
            child: Text(
              '退出登录',
              style: TextStyle(color: Colors.black),
            ),
          ),
        ),
      ),
    );
  }
}